package main

import (
	"02demo-iris-mysql/conf"
	"02demo-iris-mysql/route"
	"flag"

	_ "02demo-iris-mysql/docs"

	swagger "github.com/iris-contrib/swagger/v12"
	swaggerFiles "github.com/iris-contrib/swagger/v12/swaggerFiles"
	iris "github.com/kataras/iris/v12"
)

func main() {
	flag.Parse()
	app := newApp()

	//swagger config
	config := &swagger.Config{
		URL: "http://localhost:7070/swagger/doc.json", //The url pointing to API definition
	}
	app.Get("/swagger/{any}", swagger.CustomWrapHandler(config, swaggerFiles.Handler))
	// 初始化路由
	route.InitRouter(app)

	err := app.Run(
		// port
		iris.Addr(":"+conf.Sysconfig.Port),
		iris.WithoutServerError(iris.ErrServerClosed))
	if err != nil {
		panic(err)
	}
}

func newApp() *iris.Application {

	app := iris.New()
	app.Configure(iris.WithOptimizations)
	// 允许跨域
	app.AllowMethods(iris.MethodOptions)
	return app
}
